﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Extentions;

namespace LibNiconico.NiconicoApi.Videos.Comments.Message
{
    /// <summary>
    /// ニコニコ動画メッセージ問い合わせ情報
    /// </summary>
    public sealed class NicoVideoMessageQueryInfo:NicoUrlAble
    {
        /// <summary>
        /// メッセージサーバURL
        /// </summary>
        public Uri Ms { get; set; }

        /// <summary>
        /// スレッド番号
        /// </summary>
        public string Thread { get; set; }

        /// <summary>
        /// バージョン
        /// </summary>
        public string Version { get; set; }

        /// <summary>
        /// 遡って取得するコメント数
        /// </summary>
        public int ResFrom { get; set; }

        /// <summary>
        /// 不明
        /// </summary>
        public int ResBefore { get; set; }

        /// <summary>
        /// 過去コメント取得キー
        /// </summary>
        public string WayBackKey { get; set; }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        public NicoVideoMessageQueryInfo()
        {
            Ms = null;
            Version = "20061206";
            Thread = "";
            ResFrom = -200;
            ResBefore = 0;
            WayBackKey = "";
        }


        /// <summary>
        /// URLパスとして取得
        /// </summary>
        /// <returns></returns>
        internal override string AsPath()
        {


            return Ms.LocalPath+ (Ms.LocalPath[Ms.LocalPath.Length - 1] == '/' ? "" : "/") + "thread";
        }


        /// <summary>
        /// URL問い合わせ文字列として取得
        /// </summary>
        /// <returns></returns>
        internal override string AsQuery()
        {
            QueryStrings query = new QueryStrings();
            query.Add("version", this.Version);
            query.Add("thread", this.Thread);
            query.Add("res_from", this.ResFrom.ToString());
            if(this.ResBefore > 0)query.Add("res_before", this.ResBefore.ToString());
            if (WayBackKey != "") query.Add("waybackkey", this.WayBackKey);

            return query.ToString();
        }


    }
}
